package com.digitalgeko.pruebasdeconcepto.fragments;

import com.digitalgeko.pruebasdeconcepto.R;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListFragment extends android.support.v4.app.ListFragment {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", 
				"Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" };
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, values);
		 
		setListAdapter(adapter);
	}
	
	@Override
	//al hacer tap en algun elemento de la vista, setea el texto del elemento en el nuevo fragment
	public void onListItemClick(ListView l, View v, int position, long id) {
		String item = (String) getListAdapter().getItem(position);
		DetailFragment fragment = (DetailFragment) getFragmentManager().findFragmentById(R.id.detalleFragment);
		if (fragment != null && fragment.isInLayout()) {
			fragment.setText(item);
		} else {
			Intent intent = new Intent(getActivity().getApplicationContext(), com.digitalgeko.pruebasdeconcepto.DetailActivity.class);
			intent.putExtra("value", item);
			startActivity(intent);
		}
	}
	
}
